package com.earl.eatbao.web;

import static org.slf4j.LoggerFactory.getLogger;

import java.util.List;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.earl.eatbao.commons.vo.ResultMessage;
import com.earl.eatbao.domain.eatbao.Message;
import com.earl.eatbao.service.MessageService;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

/**
 * @author Administrator
 * @version 1.0
 * @created 23-十一月-2016 16:55:14
 */
@RestController
@RequestMapping("/message")
public class MessageController extends BaseController {

		// desc:日记工具logger
		private static final Logger logger = getLogger(MessageController.class);

	    @Autowired
	    private MessageService messageService;
	
		/**
		 * 查找所有系统消息
		 */
		@ApiOperation(value = "查找所有系统消息", notes = "查找所有系统消息", httpMethod = "GET", response = String.class)
		@RequestMapping(value="/findAll",  method = RequestMethod.GET)
		public ResponseEntity<ResultMessage> findAll(){

			logger.info("<====== 进入findAll:方法,{[] : } ====");
			// desc: 封装操作结果
			ResultMessage result = new ResultMessage();
			result.getResultParm().put("messageList",(List<Message>)messageService.findAll());
			result.setMessageCode(200l);
			result.setResultInfo("请求操作成功");

			logger.info("==== 退出findAll方法 返回值类型:{ ResponseEntity<ResultMessage>: } =======>");
			return new ResponseEntity<ResultMessage>(result, HttpStatus.OK);
		}
		/**
		 * 查找指定用户所有系统消息
		 * @param userId
		 * @return
		 */
		@ApiOperation(value = "查找指定用户所有系统消息", notes = "查找指定用户所有系统消息", httpMethod = "POST", response = String.class)
		@RequestMapping(value="/findUserMessage",  method = RequestMethod.POST)
		public ResponseEntity<ResultMessage> findUserMessage(
				@ApiParam(name = "userId", required = true, value = "用户ID")
				@RequestParam(name = "userId", required = true)Long userId){

			logger.info("<====== 进入findUserMessage:方法,{[userId] :" +userId + " } ====");
			// desc: 封装操作结果
			ResultMessage result = new ResultMessage();
			result.getResultParm().put("messageList",messageService.findByUserId(userId));
			result.setMessageCode(200l);
			result.setResultInfo("请求操作成功");

			logger.info("==== 退出findUserMessage方法 返回值类型:{ ResponseEntity<ResultMessage>: } =======>");
			return new ResponseEntity<ResultMessage>(result, HttpStatus.OK);
		}

		/**
		 * 查找指定用户未读系统消息
		 * @param userId
		 * @return
		 */
		@ApiOperation(value = "查找指定用户未读系统消息", notes = "查找指定用户未读系统消息", httpMethod = "GET", response = String.class)
		@RequestMapping(value="/findUserUnreadMessage",  method = RequestMethod.GET)
		public ResponseEntity<ResultMessage> findUserUnreadMessage(
				@ApiParam(name = "userId", required = true, value = "用户ID")
				@RequestParam(name = "userId", required = true) Long userId){
			logger.info("<====== 进入findUserUnreadMessage:方法,{[userId] :" + userId + " } ====");
			List<Message> findAll = (List<Message>)messageService.findAll();
			// desc: 封装操作结果
			ResultMessage result = new ResultMessage();
			result.getResultParm().put("messageList", messageService.findByUserIdAndRead(userId));
			result.setMessageCode(200l);
			result.setResultInfo("请求操作成功");

			logger.info("==== 退出findUserUnreadMessage方法 返回值类型:{ ResponseEntity<ResultMessage>: } =======>");
			return new ResponseEntity<ResultMessage>(result, HttpStatus.OK);
		}
		
}